﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetworkSimulator
{
    public class BCRA : Routing
    {
        public BCRA()
            : base()
        {

        }

        /*******************************************************************
         *  BCRA (Bandwidth Constrained Routing Algorithm)
         *  
         *  CODER:  HOANG CHUNG HIEN
         *  DATE:   29/3/2013
         *  VERSION: 1.0
         *  
         *******************************************************************/
        public override Path  getPath(Request req)
        {
            this.Renew();
            this.removeLinks(req.Bandwidth);

            // If had at least one path from req.source to req.destination
            if (BFS(nodes[req.Source], nodes[req.Destination]).Links.Count > 0)
            {
                // Calculate link weight
                foreach (Node node in map.Nodes)
                    foreach (Link link in node.Links)
                    {
                        if (usable_bw[link] > 0)
                        {
                            cost[link] = (Math.Pow(10, 8) / link.Capacity) * (link.UsingBandwidth / link.Capacity) + 1;
                        }
                    }

                // Use Dijkstra to get path
                return dijkstra(nodes[req.Source], nodes[req.Destination]);
            }

            return new Path();
        }
        //=============================================================================

    }
}
